<?php
namespace app\admin\controller;
use think\Controller;
use think\Request;
class MemberLevel extends Controller
{
	public function lst()
	{	
		$memberLevelRes=db('memberLevel')->select();
		$settitle=settitle('会员级别');
		$this->assign(
			array(
				'settitle'=>$settitle,
				'memberLevelRes'=>$memberLevelRes
			));
		return view();
	}
	public function add()
	{		
		if(request()->isPost())
		{
			$data=input('post.');
			//验证
  /*  		$validate = validate('type');
    		if(!$validate->check($data)){
			    $this->error($validate->getError());
			}*/
			//处理上传图片

			$add=db('memberLevel')->insert($data);
			if($add)
			{
				$this->success('添加会员级别成功',url('lst'));
			}else
			{
				$this->error('添加会员级别失败');
			}
		}
		$settitle=settitle('会员级别');
		$this->assign('settitle',$settitle);
		return view();
	}

	public function edit()
	{	
		$id=input('id');
		if(request()->isPost())
		{	
			$data=input('post.');
			//验证
/*    		$validate = validate('type');
    		if(!$validate->check($data)){
			    $this->error($validate->getError());
			}*/
			//处理上传图片
			$save=db('memberLevel')->update($data);
			if($save!==false)
			{
				$this->success('修改会员级别成功',url('lst'));
			}else
			{
				$this->error('修改会员级别失败');
			}
		}
		$memberLevels=db('memberLevel')->find($id);

		$settitle=settitle('会员级别');
		$this->assign(
			array(
			'memberLevels'=>$memberLevels,
			'settitle'=>$settitle,
		)
	);
		return view();
	}

	public function del($id)
	{	
		$del=db('memberLevel')->delete($id);
		if($del)
		{
			$this->success('删除会员界别成功',url('lst'));
		}else
		{
			$this->error('删除会员界别失败');
		}
	}
}
